﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NetAutoGUI;

namespace AutoWx
{
    public class Window对象操作和使用
    {
        public void Wx()
        {
            Window? win = GUI.Application.FindWindowLikeTitle("微信");
            if (win == null)
            {
                // 获取给定图像的坐标
                Rectangle? rectangle = GUI.Screenshot.LocateOnScreen("wx.png");
                if (rectangle != null)
                {
                    GUI.Mouse.Click(rectangle.X, rectangle.Y);
                    win = GUI.Application.WaitForWindowByTitle("微信");
                }
                else
                {
                    Console.WriteLine("在系统托盘中没找到微信");
                    return;
                }
            }
            else
            {
                win.Activate();
            }
            win.WaitAndClick("meinv.png",0.8);
            for (int i = 0; i < 10; i++)
            {
                GUI.Keyboard.Write("这是我用程序自动输入的");
                GUI.Keyboard.Press(VirtualKeyCode.RETURN);
                Thread.Sleep(100);
            }
        }
        public void AA()
        {
            Window? win = GUI.Application.FindWindowLikeTitle("微信");
            if (win == null)
            {

                // 获取给定图像的坐标
                Rectangle? rectangle = GUI.Screenshot.LocateOnScreen("wx.png");
                if (rectangle != null)
                {
                    GUI.Mouse.Click(rectangle.X, rectangle.Y);
                    win = GUI.Application.WaitForWindowByTitle("微信");
                }
                else
                {
                    Console.WriteLine("在系统托盘中没找到微信");
                    return;
                }
            }
            else
            {
                win.Activate();
                //GUI.Keyboard.Write("输入指定字符");
                //GUI.Keyboard.HotKey(VirtualKeyCode.CONTROL,VirtualKeyCode.VK_V);
                // 根据给定图像匹配然后点击
                //win.WaitAndClick("icon.png");
                //win.WaitAndClick("gg.png");
            }
            win.WaitAndClick("meinv.png");
            
            /*
            Rectangle? r = win.Locate("icon.png");
            
            if (r != null)
            {
                win.Click(r.X + (r.Width / 2), r.Y + (r.Height/2));
            }
            */
        }
        public void MM()
        {

            Window? win = GUI.Application.FindWindowLikeTitle("*记事本*");
            if (win != null)
            {
                // 激活窗口
                win.Activate();
                // 最大化
                win.Maximize();
                // 点击编辑-替换菜单
                //win.GetMainMenu().编辑.替换();
                // 移动鼠标到指定位置
                win.MoveMouseTo(200,300);
                // 双击鼠标左键
                win.DoubleClick(200,250);
                // 单机鼠标右键
                win.Click(button: MouseButtonType.Right);
            }
        }
    }
}
